package com.liao.web.servlet;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.liao.domain.Province;
import com.liao.service.ProvinceService;
import com.liao.service.impl.ProvinceServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
//下面两个请求网址都行
//http://localhost:8888/shengf/uqnasjkcn
//http://localhost:8888/olg
@WebServlet("/olg")
public class ProvinceServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.调用service
        ProvinceService service = new ProvinceServiceImpl();
        String json = service.findAllJson();
        System.out.println(json);

        //2.响应结果
        response.setContentType("application/json;charset=utf-8");
        response.getWriter().write(json);
    }
}
